package org.example.command;

import org.example.model.HTMLDocument;

import java.io.IOException;

public class SaveCommand implements Command {
    private HTMLDocument htmlDocument;
    private String filepath;

    private SaveCommand(HTMLDocument htmlDocument, String filepath) {
        this.htmlDocument = htmlDocument;
        this.filepath = filepath;
    }

    public static SaveCommand create(HTMLDocument htmlDocument, String filepath){
        return new SaveCommand(htmlDocument,filepath);
    }
    @Override
    public boolean execute() {
        try {
            htmlDocument.saveToFile(filepath);  // 保存 HTML 文档到指定路径
            System.out.println("文件保存成功: " + filepath);
        } catch (IOException e) {
            System.err.println("保存文件失败: " + e.getMessage());
            return false;
        }
        return true;
    }

}
